#include "hdl_led.h"

static BOOL led_status = OFF;

int8_t hdl_led_onoff(BOOL onoff)
{
	if(onoff == ON)
	{
		GPIO1->DR &= ~(1<<3);	/* 打开LED0 */
	}
	else if(onoff == OFF)
	{
		GPIO1->DR |= (1<<3);	/* 关闭LED0 */
	}
	else
	{
		GPIO1->DR |= (1<<3);	/* 关闭LED0 */
	}
	return (int8_t)onoff;
}

int8_t hdl_led_toggel(void)
{
	led_status == ON?(hdl_led_onoff(ON),led_status = OFF):(hdl_led_onoff(OFF),led_status = ON);
	return led_status;
}

int8_t hdl_led_init(void)
{
	/* 1、初始化IO复用 */
	IOMUXC_SetPinMux(IOMUXC_GPIO1_IO03_GPIO1_IO03,0);		/* 复用为GPIO1_IO03 */	
	/* 2、、配置GPIO1_IO03的IO属性	
	 *bit 16:0 HYS关闭
	 *bit [15:14]: 00 默认下拉
	 *bit [13]: 0 kepper功能
	 *bit [12]: 1 pull/keeper使能
	 *bit [11]: 0 关闭开路输出
	 *bit [7:6]: 10 速度100Mhz
	 *bit [5:3]: 110 R0/6驱动能力
	 *bit [0]: 0 低转换率
	 */
	IOMUXC_SetPinConfig(IOMUXC_GPIO1_IO03_GPIO1_IO03,0X10B0);
	
	/* 3、初始化GPIO,GPIO1_IO03设置为输出*/
	GPIO1->GDIR |= (1 << 3);	 

	hdl_led_onoff(OFF);
	DBG_MSG("led init\r\n");
	return SUCCESS;
}

struct hal_led_if g_hdl_led_if =
{
	.led_init = hdl_led_init,
	.led_onoff = hdl_led_onoff,
	.led_toggle = hdl_led_toggel,
};

